//
//  UIButton＋Extension.swift
//  Weibo
//
//  Created by 冯童童 on 16/1/17.
//  Copyright © 2016年 冯童童. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(imageName : String?, backImageName : String?) {
        self.init()
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
            setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)

        }
               if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Highlighted)
        }
        
        sizeToFit()
        
    }
    
    
    convenience init(title : String,fontSize : CGFloat, color : UIColor, backImageName : String?, imageName : String? = nil){
        self.init()
        
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        
    }
    
}
